package com.nexus.ai.embed;

import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.embedding.EmbeddingRequest;
import org.springframework.ai.embedding.EmbeddingResponse;
import org.springframework.ai.ollama.api.OllamaEmbeddingOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 向量数据库操作
 * @Date 2025/9/28 18:26
 * @Author luzhengning
 **/
@Service
public class NexusEmbedService {
    
    /**
     * 向量模型
     * @Date 2025/9/28 18:27
     * @Author luzhengning
     **/
    @Autowired
    private EmbeddingModel embeddingModel;

    /**
     * 获取向量数据
     * @Date 2025/9/29 03:40
     * @Author luzhengning
     **/
    public EmbeddingResponse embedding() {
        System.out.println("向量维度"+embeddingModel.dimensions());
        EmbeddingRequest request=new EmbeddingRequest(
                List.of("牛肉面","小猫"), //嵌入的文本列表
                OllamaEmbeddingOptions.builder()    //ollama配置选项
                        .model("dengcao/Qwen3-Embedding-0.6B:F16")  //可以指定向量模型
                        .truncate(false)    //遇长文本不截断
                        .build()
        );
        EmbeddingResponse response=embeddingModel.call(request);
        return response;
        //可以使用快捷方法
        //return embeddingModel.embed(List.of("大猫","小猫"));

    }

    
}
